package edu.nf.project.mappers.storeOperation.convention;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import edu.nf.project.entitys.entity.other.dto.CustomerOrderInfoDTO;
import edu.nf.project.entitys.entity.storeOperation.convention.operate.CustomerOrder;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.web.bind.annotation.RequestParam;

import java.io.Serial;
import java.util.Date;
import java.util.List;

/**
 * 订单 Mapper 接口
 */
@Mapper
public interface CustomerOrderMapper extends BaseMapper<CustomerOrder> {
    @Update("update customer_order set total_amount = total_amount + #{order.payableAmount}," +
            "payable_amount = payable_amount + #{order.payableAmount} " +
            "where order_id = #{order.orderId}")
    void updateTotalAmount(@Param("order") CustomerOrder order);

    @Select("select * from customer_order co\n" +
            "where co.u_id = #{uId} and order_type = 2 \n" +
            "and order_status = 0 \n" +
            "and place_order_time >= #{oneHourAgo}\n" +
            "and NOT EXISTS (\n" +
            "    SELECT 1 \n" +
            "    FROM refund_request rr \n" +
            "    WHERE rr.order_id = co.order_id and request_status <> 3);")
    List<CustomerOrder> listCanRefundOrder(Integer uId, Date oneHourAgo);
} 